#include "homepage.h"

#include "ui_homepage.h"
#include "qclickwidget.h"

#include "common/constants.h"
//
#include "custom/customtoast.h"



// 正确：在这里初始化变量
bool mCurrentSerialPortStatus = false;

//全局



HomePage::HomePage(QWidget *parent):QWidget(parent),ui(new Ui::HomePage),mIniFile(new IniFile()){
    //
    ui->setupUi(this);
    //这是调用当前对象（假设当前对象是一个继承自QDialog的类实例）的
    // this->setStyleSheet("QDialog { border: none; margin: 0px; }");
    // 移除所有框架提示
    // this->setWindowFlags(Qt::FramelessWindowHint);
    //全屏
    // this->showFullScreen();
    //
    // this->showMaximized();//最大化
    //置顶显示
    // this->setWindowFlag(Qt::WindowStaysOnTopHint, true);

    //


    //头部
    ui->headWidget->setStyleSheet("background-color: rgb(255,255, 255);"); // 蓝色，50%透明度
    //头方法调用
    HeadMethod();
    //中部
    ui->middleWidget->setStyleSheet("background-color: rgb(230,230,230);");
    //中部方法
    MiddleMethod();
    //底部
    ui->bottomWidget->setStyleSheet("background-color: rgb(255,255, 255);");
    //底部方法
    BottomMethod();


}

HomePage::~HomePage()
{
    delete ui;
}

/**
 * 头方法实现
 * @brief HomePage::HeadMethod
 */
void HomePage::HeadMethod(){
    // 定时更新时间显示
    mQTimer = new QTimer(this);
    //连接槽
    connect(mQTimer, &QTimer::timeout, this, &HomePage::updateTime);
    //启动时间
    mQTimer->start(1000); // 每秒更新一次时间
    //当前软件版本
    ui->VersionNumber->setText(mIniFile->CurrentVersionNumber());


}

/**
 * 系统时间
 * @brief updateTime
 */
void HomePage::updateTime(){
    // 获取当前日期和时间
    QDateTime mQDateTime = QDateTime::currentDateTime();
    // 获取当前日期
    QDate currentDate = mQDateTime.date();
    // 获取当前时间并转换为字符串
    QString currentTime = mQDateTime.currentDateTime().toString("yyyy-MM-dd HH:mm:ss");
    //设置时间
    ui->systemTime->setText(currentTime);
    // 获取当前是星期几（Qt::DayOfWeek枚举）
    int dayOfWeek = currentDate.dayOfWeek();
    // 将枚举值转换为可读的字符串（这里以英文为例，你可以根据需要替换为本地化的字符串）
    QString dayOfWeekString = ui->whatDay->text();
    if(dayOfWeekString == ""){
        //获取
        switch (dayOfWeek) {
        case Qt::Sunday:
            dayOfWeekString = "星期日";
            break;
        case Qt::Monday:
            dayOfWeekString = "星期一";
            break;
        case Qt::Tuesday:
            dayOfWeekString = "星期二";
            break;
        case Qt::Wednesday:
            dayOfWeekString = "星期三";
            break;
        case Qt::Thursday:
            dayOfWeekString = "星期四";
            break;
        case Qt::Friday:
            dayOfWeekString = "星期五";
            break;
        case Qt::Saturday:
            dayOfWeekString = "星期六";
            break;
        }
        ui->whatDay->setText(dayOfWeekString);
    }



}

/**
 * 中部方法
 * @brief HomePage::BottomMethod
 */
void HomePage::MiddleMethod(){

    // 设置tab位置为None，从而不显示标签
    ui->tabWidget->tabBar()->hide();
    //设置默认显示第一页
    ui->tabWidget->setCurrentIndex(0);

    //全部图像-----背景
    ui->AllimagesWidget->setStyleSheet("background-color: rgb(255,255, 255);");
    //连接——————全部图像
    connect(ui->tabAllimagesWidget, &QClickWidget::CustomSignalSaveSettings, this, &HomePage::triggerAllImages);
    //连接——————相机设置
    connect(ui->tapCameraSettings, &QClickWidget::CustomSignalSaveSettings, this, &HomePage::triggerCameraSettings);
    //连接——————图像曲线
    connect(ui->tapImageCurveWidget, &QClickWidget::CustomSignalSaveSettings, this, &HomePage::triggerImageCurve);
    //相机设置-----背景
    ui->CameraSettings->setStyleSheet("background-color: rgb(255,255, 255);");
    //图像曲线-----背景
    ui->ImageCurveWidget->setStyleSheet("background-color: rgb(255,255, 255);");
    //方案设置-----背景
    ui->optionWidget->setStyleSheet("background-color: rgb(255,255, 255);");
    //获取串口列表
    Get_serial_port_list();
    //连接——————打开串口
    connect(ui->OpenSerialPort,&QPushButton::clicked,this,&HomePage::Open_serial_port);
    //连接——————刷新串口
    connect(ui->refresh_serial_port,&QPushButton::clicked,this,&HomePage::Get_serial_port_list);
    //图像配置的TAB
    ui->GraphicsTab->tabBar()->hide();
    //设置默认显示第一页
    ui->GraphicsTab->setCurrentIndex(0);
    //全部相机
    ui->CameraOne->setStyleSheet("background-color: rgb(255,255,255);");
    ui->CameraTwo->setStyleSheet("background-color: rgb(255,255,255);");
    //相机设置
    ui->widget_9->setStyleSheet("background-color: rgb(255,255,255);");
    ui->widget_10->setStyleSheet("background-color: rgb(255,255,255);");
}







// 全部图像————————槽
void HomePage::triggerAllImages(){
    //切换TAB
    ui->GraphicsTab->setCurrentIndex(0);
}
// 相机设置————————槽
void HomePage::triggerCameraSettings(){
    //切换TAB
    ui->GraphicsTab->setCurrentIndex(1);
}
// 图像曲线————————槽
void HomePage::triggerImageCurve(){
    //切换TAB
    ui->GraphicsTab->setCurrentIndex(2);
}











/**
 * 打开串口
 * @brief HomePage::Open_serial_port
 */
void HomePage::Open_serial_port(){
    CustomToast *mCustomToast = new CustomToast();
    mCustomToast->setAlignment(CustomToast::Center);
    mCustomToast->setText("-----------------------");
    mCustomToast->setBackgroundColor(QColor(200,200,200));
    mCustomToast->setDuration(1000);
    mCustomToast->show();
}



/**
 * 获取串口列表
 * @brief HomePage::Get_serial_port_list
 */
void HomePage::Get_serial_port_list(){



}





/**
 * 底部方法
 * @brief HomePage::BottomMethod
 */
void HomePage::BottomMethod(){
    // connect(ui->saveSettings,&QWidget::)



    //连接——————隐藏
    connect(ui->tapHiddenWidget, &QClickWidget::CustomSignalSaveSettings, this, &HomePage::triggerHidden);
    //连接——————查看图像
    connect(ui->ViewImage, &QClickWidget::CustomSignalSaveSettings, this, &HomePage::triggerViewImage);
    //连接——————通讯设置
    connect(ui->CommunicationSetup, &QClickWidget::CustomSignalSaveSettings, this, &HomePage::triggerCommunicationSetup);
    //连接——————统计管理
    connect(ui->StatisticalManagement, &QClickWidget::CustomSignalSaveSettings, this, &HomePage::triggerStatisticalManagement);
    //连接——————启动
    connect(ui->activate, &QClickWidget::CustomSignalSaveSettings, this, &HomePage::triggerActivate);

}





/**
 * 保存设置————————槽
 * @brief HomePage::SaveSettings
 */
void HomePage::triggerSaveSettings(){
    qDebug() << "保存设置————————槽";
}

/**
 * 隐藏————————槽
 * @brief HomePage::triggerHidden
 */
void HomePage::triggerHidden(){
    showMinimized();//最小化
}

/**
 * 查看图像————————槽
 * @brief HomePage::triggerViewImage
 */
void HomePage::triggerViewImage(){
    //切换TAB
    ui->tabWidget->setCurrentIndex(0);
}


/**
 * 通讯设置————————槽
 * @brief HomePage::triggerCommunicationSetup
 */
void HomePage::triggerCommunicationSetup(){
    //切换TAB
    ui->tabWidget->setCurrentIndex(1);
}


/**
 * 统计管理————————槽
 * @brief HomePage::triggerStatisticalManagement
 */
void HomePage::triggerStatisticalManagement(){
    qDebug() << "统计管理————————槽";
    //切换TAB
    ui->tabWidget->setCurrentIndex(2);
}



/**
 * 启动————————槽
 * @brief HomePage::triggerActivate
 */
void HomePage::triggerActivate(){
    qDebug() << "启动————————槽";
}



